﻿Imports EShop.VBClass
Partial Class lmenus
    Inherits System.Web.UI.Page

    Dim strClassList As String = ""
    Dim topDegree As Integer = 0
    Dim clsTopid As Integer = 0
    ''' <summary>
    ''' 获取后台产品分类
    ''' </summary>
    ''' <param name="topId">顶级菜单ID</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function getClassListA(topId As Integer, Optional isTop As Boolean = True) As String
        Dim topclsName As String = "总体分类"
        Dim tBid As String = "", t_id As Integer
        Dim strCond As String = " meu_parentid=" & topId & " and meu_Type=1"
        Dim pdCountField As String = " ", strpCount As String = ""
        If isTop Then
            strClassList = "<div class=""clsTop"">系统菜单 &nbsp;&nbsp; <a href=""menuadd.aspx?clspid=" & t_id & "&clstid=" & t_id & """  title=""添加子菜单""  >+</a></div>" & vbCrLf
        End If

        Dim subNum As Integer = 0, pSort As Integer = 0


        Dim dtClass As Data.DataTable = GetDataTable("Lmenus", "*", strCond, "meu_pSort desc")
        Dim dtClass2 As Data.DataTable = Nothing
        Dim cls_Name As String, cls_id, cls_Degree As Integer, degree As Integer = 0, strL As String = " └ "
        Dim isShow As Boolean
        If dtClass IsNot Nothing Then
            Dim rCount As Integer = dtClass.Rows.Count
            Dim pCount As Integer = 0
            'strClassList &= " <ul>" & vbCrLf
            For r As Integer = 0 To rCount - 1
                cls_Name = dtClass.Rows(r)("meu_Name").ToString
                cls_id = dtClass.Rows(r)("id")
                cls_Degree = dtClass.Rows(r)("meu_Degree")
                isShow = dtClass.Rows(r)("meu_isshow")
                pSort = dtClass.Rows(r)("meu_pSort")
                If isTop Then topDegree = cls_Degree - 1
                degree = cls_Degree - topDegree
                If Not isShow Then
                    cls_Name = "<span class=dgray>" & cls_Name & " [隐]</span>"
                End If
                Dim sParameter() As Data.SqlClient.SqlParameter = { _
                    New Data.SqlClient.SqlParameter("@parentID", cls_id) _
                   , New Data.SqlClient.SqlParameter("@tableName", "lmenus") _
                   , New Data.SqlClient.SqlParameter("@parentidField", "meu_parentid") _
                }

                strClassList &= "<li class=""classA" & degree & """> <a href=""menuadd.aspx?clsid=" & cls_id & "&clstid=" & clsTopid & """ title=""修改菜单"">" & strL & cls_Name & "</a> &nbsp;<span class=org>[" & pSort & "]</span>" & strpCount
                strClassList &= " &nbsp; &nbsp; <a href=""menuadd.aspx?clspid=" & cls_id & "&clstid=" & clsTopid & """ title=""添加子菜单""  >+</a> &nbsp;&nbsp; <a href=""menudel.aspx?clsdid=" & cls_id & "&clstid=" & clsTopid & """ title=""删除菜单"" onclick=""javascript:return confirm('确定删除吗？删除后不可恢复哦！')"" >-</a></li>" & vbCrLf
                dtClass2 = GetDataTableP("getSubclassNum ", sParameter)
                subNum = dtClass2.Rows(0)("subnum")
                If subNum > 0 Then
                    strClassList = getClassListA(cls_id, False)
                End If
            Next
            'strClassList &= "</ul>" & vbCrLf
        End If
        Return strClassList
    End Function

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        checkSessionTimeout(Me)
        If Session("admin_role") > 1 Then
            ExecuteJSalert(Me, "对不起您！没有管理此项的权限！")
        Else
            checkData(Me)
            Me.divClassList.InnerHtml = getClassListA(0)
        End If

    End Sub
End Class
